package yunhe.servlet;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import yunhe.biz.ISaleBiz;
import yunhe.biz.impl.SaleBizImpl;
import yunhe.entity.SaleAppend;
import yunhe.entity.SalePack;
import yunhe.util.GeneralUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/6/20.
 */
@WebServlet(name = "SalePackByDateServlet",urlPatterns = "/sale/SalePackByDateServlet")
public class SalePackByDateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Date startDate= GeneralUtil.stringToUtilDate( request.getParameter("startDate"),"yy-MM-dd");
        Date endDate=GeneralUtil.stringToUtilDate( request.getParameter("endDate"),"yy-MM-dd");
        ISaleBiz iSaleBizImpl = new SaleBizImpl();
        List<SalePack> list = iSaleBizImpl.salePackQueryByDate(startDate,endDate);
        JSONArray ja=new JSONArray();

        for(SalePack salePack:list){
            JSONObject jbj=new JSONObject(salePack);
            try {
                jbj.put("cusId",salePack.getCustomer().getCusId());
                jbj.put("proBarCode",salePack.getProduct().getProBarCode());
            }catch (JSONException e){
                e.printStackTrace();
                System.out.println();
            }
            ja.put(jbj);
        }
        response.getWriter().print(ja.toString());
    }
}
